﻿using System;
using CkSoftware.GroupMe.Sdk.Core.Dao;
using Newtonsoft.Json;

namespace CkSoftware.GroupMe.Sdk.Helpers.Users.Dao
{
	/// <summary>
	/// The data object for the currently authenticated user.
	/// </summary>
	public class UserInfo
	{
		/// <summary>
		/// The user-id.
		/// </summary>
		[JsonProperty(PropertyName = "id")]
		public string UserId { get; set; }

		/// <summary>
		/// The users telephone-number.
		/// </summary>
		[JsonProperty(PropertyName = "phone_number")]
		public string PhoneNumber { get; set; }

		/// <summary>
		/// The <see cref="PictureData" /> for the user avatar.
		/// </summary>
		[JsonIgnore]
		public PictureData AvatarImage
		{
			get { return new PictureData {Url = AvatarUrl}; }
		}

		/// <summary>
		/// The image-url for the user avatar.
		/// </summary>
		[JsonProperty(PropertyName = "image_url")]
		public string AvatarUrl { get; set; }

		/// <summary>
		/// The users name.
		/// </summary>
		[JsonProperty(PropertyName = "name")]
		public string Name { get; set; }

		/// <summary>
		/// The DateTime the user was created.
		/// </summary>
		[JsonIgnore]
		public DateTime CreatedAt
		{
			get { return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(CreatedAtSecondsSinceEpoch); }
		}

		/// <summary>
		/// The DateTime the user was created in unix format (seconds since epoch).
		/// </summary>
		[JsonProperty(PropertyName = "created_at")]
		public long CreatedAtSecondsSinceEpoch { get; set; }

		/// <summary>
		/// The DateTime the user was last updated.
		/// </summary>
		[JsonIgnore]
		public DateTime UpdatedAt
		{
			get { return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(UpdatedAtSecondsSinceEpoch); }
		}

		/// <summary>
		/// The DateTime the user was last updated in unix format (seconds since epoch).
		/// </summary>
		[JsonProperty(PropertyName = "updated_at")]
		public long UpdatedAtSecondsSinceEpoch { get; set; }

		/// <summary>
		/// The registered email address for this user.
		/// </summary>
		[JsonProperty(PropertyName = "email")]
		public string Email { get; set; }

		/// <summary>
		/// Defines if the SMS mode is enabled.
		/// </summary>
		[JsonProperty(PropertyName = "sms")]
		public bool SmsModeEnabled { get; set; }
	}
}